#ifndef __MY_ANO_H
#define __MY_ANO_H
#include "stm32f4xx_hal.h"

//数组下标定义
#define HEAD_INDEX															  0	//帧头数组下标
#define ADDR_INDEX																1	//目标地址数组下标
#define ID_INDEX																	2	//功能ID数组下标
#define LEN_INDEX																	3	//数据长度数组下标
#define DATA_HEAD_INDEX			    									4   //数据部分的起始下标
#define SC_INDEX(struct)													(DATA_HEAD_INDEX+struct->data_len)
#define AC_INDEX(struct)		    									(SC_INDEX(struct)+1)

//强制类型转换+以一个字节为步长进行寻址
#define ONEBYTE_ADDRESSING(data_pointer,index)		(*(((uint8_t*)(data_pointer)+index)))

//目标地址定义
#define FRAME_HEADER 															0XAA   //匿名协议固定帧头
#define GENERAL_OUTPUT_ADDR												0XFF   //广播型输出
#define HOST_ADDR																	0XAF   //向上位机输出
#define PRO_ADDR																	0X05   //拓空者PRO飞控
#define SHUCHUAN_ADDR															0X10   //匿名数传
#define GUANGLIU_ADDR														  0X22   //匿名光流
#define UWB_ADDR																	0X30   //匿名UWB
#define IMU_ADDR																	0X60   //匿名凌霄IMU
#define LINGXIAO_ADDR															0X61   //匿名凌霄飞控
//32位数据进行四个字节剥离拆分
#define BYTE0(temp)																(*(char*)(&temp))
#define BYTE1(temp)																(*((char*)(&temp)+1))
#define BYTE2(temp)																(*((char*)(&temp)+2))
#define BYTE3(temp)																(*((char*)(&temp)+3))

//数据帧的7个部分标记
enum FRAME_PART
{
	HEAD_PART=0,
	ADDR_PART,
	ID_PART,
	DATA_LEN_PART,
	DATA_PART,
	SC_PART,
	AC_PART
};
//信息输出颜色
enum MESSAGE_COLOR
{
	ANO_BLACK=0,
	ANO_RED,
	ANO_GREEN
};
//参数结构体
typedef struct 							
{
	uint16_t par_id;
	int32_t par_val;
}par_struct;

typedef struct
{
	uint8_t head;							//帧头
	uint8_t target_addr;			//输出目标
	uint8_t function_id;			//该帧要实现某功能的功能id
	uint8_t data_len;					//数据长度
	uint8_t data[40];				  //协议最高只支持40字节数据  
	uint8_t sum_check;				//校验和
	uint8_t add_check;				//附加校验
}ano_frameStruct;




extern par_struct target_val;

void ano_frame_init(void);
void ano_frame_reset(ano_frameStruct* frame);
void ano_par_struct_config(par_struct* parameter,uint16_t par_id,int32_t par_val);
void ano_send_string(uint8_t color,char* str);
void ano_send_message(char* str,int32_t value);
void ano_send_flexible_frame(uint8_t id,int32_t x_coordinate,int32_t y_coordinate);
void ano_send_parameter_frame(uint16_t par_id,int32_t par_val);
void ano_read_one_byte(uint8_t data);


#endif